﻿package com.wandian.model.socket.net
{
	import com.wandian.ApplicationFacade;
	import com.wandian.controller.CLZNoticeName;
	import com.wandian.data.GameData;
	import com.wandian.util.CLZTiming;

	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IOErrorEvent;
	import flash.events.ProgressEvent;
	import flash.events.SecurityErrorEvent;
	import flash.net.Socket;
	import flash.utils.ByteArray;
	import flash.utils.Dictionary;
	import flash.utils.Endian;

	import flashx.textLayout.elements.BreakElement;

	import org.hamcrest.object.nullValue;

	/**
	* @author long
	* @QQ 108232706
	* @version 1.0
	*/
	public class TcpSocket extends EventDispatcher
	{
		private var _socket:Socket=null;
		private var _packet:ByteArray=null;
		private var _packetLen:uint=0;
		private var _packetBody:ByteArray=null;
		private var _readPacket:ByteArray=null;
		private var _nStatus:int=0;
		private var _nReadPos:int=0;
		private var _nBodyLen:uint=0;
		private var _ndx:int=0;
		private const REQ_REQUEST:int=0;
		private const REQ_HEADER:int=1;
		private const REQ_BODY:int=2;
		private const REQ_DONE:int=3;
		private const REQ_PROCESS:int=4;
		private const REQ_ERROR:int=5;
		private const PACKET_HEADER_SIZE:int=22; //6;
		private const PACKET_BUFFER_SIZE:int=16384;
		private var _host:String="";
		private var _port:int=0;
		private var _connected:Boolean=false;
		private var _global:GameData;
		private var readBodyPos:int=22; //读取body部分的指针
		public var HEADER:int=29099;
		public var cmdMap:Dictionary=new Dictionary();

		public function TcpSocket(param1:Boolean=false, param2:String="String")
		{
			this._global=GameData.getInstance();
			this._packet=new ByteArray();
			this._packetBody=new ByteArray();
			this._readPacket=new ByteArray();
			this._readPacket.endian=Endian.LITTLE_ENDIAN;
			this._packet.endian=Endian.LITTLE_ENDIAN;
			this._packetBody.endian=Endian.LITTLE_ENDIAN;
			cmdMap[1000]="CMD_LOGIN";
			cmdMap[1001]="CMD_REQUESTFRIENDLIST";
			cmdMap[2000]="CMD_RoomList";

			cmdMap[2001]="CMD_RoomUserList";
			cmdMap[2002]="CMD_FriendList";

			cmdMap[3997]="CMD_REGISTER";
			cmdMap[3998]="LobbyCmd";
			cmdMap[3999]="GameRoomCmd";
			cmdMap[4000]="EnterRoomCmd";
			cmdMap[4001]="CMD_ROOMINFO";
			cmdMap[4002]="SitdownCmd";
			cmdMap[4003]="InGAameRoomCmd";
			cmdMap[4004]="OutGameRoomCmd";
			cmdMap[4005]="CMD_STAND_UP";
			cmdMap[4006]="CMD_START_GAME";
			cmdMap[4007]="CMD_GameMessageList";
			cmdMap[4008]="CMD_SETROOMINFO";
			cmdMap[4010]="CMD_REQUESTINFOMATION";
			cmdMap[4011]="CMD_ROOMINFOUPDATE";
			cmdMap[4012]="CMD_ROOMPLAYERNUMCHANGE";
			cmdMap[4013]="CMD_OPERATION_NEXT";
			cmdMap[4014]="CMD_OPERATION_REQUEST";
			cmdMap[4015]="CMD_OPERATION_SUCC";
			cmdMap[4016]="CMD_CUR_POT";
			cmdMap[4017]="CMD_POTS";
			cmdMap[4018]="CMD_SNAPCARDS_FLOP";
			cmdMap[4019]="CMD_SNAPCARDS_TURN";
			cmdMap[4020]="CMD_SNAPCARDS_RIVER";
			cmdMap[4021]="CMD_SHOW";

			cmdMap[5000]="CMD_GAME_OVER";
			cmdMap[5001]="CMD_UPDATE_CORNUCOPIA";
			cmdMap[5002]="CMD_REWARD_CORNUCOPIA";
			cmdMap[5003]="CMD_TODAYCORNUCOPIALIST";
			cmdMap[5004]="CMD_MYCORNUCOPIALIST";
			cmdMap[10003]="CMD_GAME_ROOM_SOCKET_CLOSE";
			return;
		}

		public function connect(host:String, port:int):void
		{
			this._host=host;
			this._port=port;
			trace("connecting:" + host, port);
			if (this._connected)
			{
				this._socket.close();
			}
			try
			{
				this._socket=new Socket();
				this._socket.endian=Endian.LITTLE_ENDIAN;
				this.reset();
				this._socket.addEventListener(IOErrorEvent.IO_ERROR, this.errorFun);
				this._socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, this.securityerrfun);
				this._socket.addEventListener(Event.CONNECT, this.connectFun);
				this._socket.connect(host, port);
			}
			catch (error:Error)
			{
				trace("connect error:" + error);
				CLZTiming.add(5, this.reConnect);
				ApplicationFacade.getInstance().sendNotification(CLZNoticeName.TIPMEDIATOR_SHOW_WINDOWS_TIP, {okNoticeName: CLZNoticeName.TIPMEDIATOR_HIDE_WINDOWS_TIP, tip: "网络错误:" + error, tipTitle: "网路提示", isCancel: false, okTip: "OK", cancelTip: "", isSendClose: true});
			}
			return;
		}

		public function writeTGW(txt:String, length:int):void
		{
			var bytes:ByteArray=new ByteArray();
			var mvalue:*="tgw_l7_forward\r\nHost: " + bytes + ":" + length + "\r\n\r\n";
			bytes.writeMultiByte(mvalue, "GBK");
			this._socket.writeBytes(bytes);
			this._socket.flush();
			return;
		}

		/**
		 * 写入开始部分，2头部+4包体长度+2命令标识+4用户id+4empty1+4empty2=22
		 * @param cmdId
		 */
		public function writeBegin(cmdId:uint):void
		{
			//将包清空
			this._packetLen=0;
			this._packet.position=0;
			this._packet.length=0;
			//包体清空
			this._packetBody.position=0;
			this._packetBody.length=0;
			this._packet.writeInt(29099); //2字节头部标识 [ab,71]				
			this._packet.writeInt(this._packetLen); //4字节包体的长度
			this._packet.writeShort(cmdId); //2字节命令标识
			this._packet.writeInt(1); //4empty1 保留位
			this._packet.writeInt(2); //4empty2 保留位
			this._packet.writeInt(3); //4empty3 保留位
			trace("[发送命令]==========out=>==========out>>>[cmd:" + cmdId + "]" + cmdMap[cmdId]);

			return;
		}

		/**
		 * 写入结束
		 */
		public function writeEnd():void
		{
			this._packet.position=4; //2;
			this._packet.writeInt(this._packetLen + this.PACKET_HEADER_SIZE);
			this._packet.position=this.PACKET_HEADER_SIZE;
			this._packet.writeBytes(this._packetBody, 0, this._packetLen);
			return;
		}

		/**
		 * 写入4个字节到包packetBody,包长度加4
		 * @param num
		 */
		public function writeInt(num:int):void
		{
			this._packetLen=this._packetLen + 4;
			this._packetBody.writeInt(num);
			return;
		}

		public function writeFloat(num:Number):void
		{
			this._packetLen=this._packetLen + 4;
			this._packetBody.writeFloat(num);
			return;
		}

		/**
		 *  写入无符号整数,4个字节到包packetBody,包长度加4
		 * @param num
		 */
		public function writeUint(num:uint):void
		{
			this._packetLen=this._packetLen + 4;
			this._packetBody.writeUnsignedInt(num);
			return;
		}

		/**
		 *  写入2个字节到包packetBody,包长度加2
		 * @param myShort
		 */
		public function writeShort(myShort:int):void
		{
			this._packetLen=this._packetLen + 2;
			this._packetBody.writeShort(myShort);
			return;
		}

		/**
		 *  写入1个字节到包packetBody,包长度加1
		 * @param myByte
		 */
		public function writeByte(myByte:int):void
		{
			this._packetLen+=1;
			this._packetBody.writeByte(myByte);
			return;
		}

		/**
		 *  写入n个字节数组到包packetBody,包长度加n
		 * @param bytes
		 */
		public function writeBytes(bytes:ByteArray):void
		{
			this._packetLen=this._packetLen + bytes.length + 4;
			this._packetBody.writeInt(bytes.length);
			this._packetBody.writeBytes(bytes);
			bytes=null;
			return;
		}

		/**
		 * 根据指定的编码写入字符串信息Strlen+1|bytes
		 * @param txt
		 * @param encoding
		 */
		public function writeString(txt:String, encoding:String="utf-8"):void
		{
			var bytes:ByteArray=new ByteArray();
			bytes.writeMultiByte(txt, encoding);
			this._packetBody.writeUnsignedInt((bytes.length + 1));
			this._packetLen=this._packetLen + 4;
			this._packetBody.writeBytes(bytes);
			this._packetBody.writeByte(int("0"));
			this._packetLen=this._packetLen + (bytes.length + 1);
			bytes=null;
			return;
		}

		/**
		 * 将对象以 AMF 序列化格式写入字节数组
		 * @param obj
		 */
		public function writeBinary(obj:Object):void
		{
			var bytes:ByteArray=new ByteArray();
			bytes.writeObject(obj);
			this._packetBody.writeUnsignedInt(bytes.length);
			this._packetLen=this._packetLen + 4;
			this._packetBody.writeBytes(bytes);
			this._packetLen=this._packetLen + bytes.length;
			bytes=null;
			return;
		}

		public function writeDate(param1:Date):void
		{
			writeShort(param1.getFullYear());
			writeByte((param1.month + 1));
			writeByte(param1.day);
			writeByte(param1.hours);
			writeByte(param1.minutes);
			writeByte(param1.seconds);
			return;
		}

		private function reset():void
		{
			this._nStatus=this.REQ_REQUEST; //读取包状态复0
			this._nReadPos=0; //当前读取位置
			this._nBodyLen=0; //body部分长度

			this._readPacket.position=0; //读包清空，置0
			this._readPacket.length=0; //
			this.datalen=0;
			this.readBodyPos=0;
			return;
		}

		private function readHeader(length:int):Boolean
		{
			do
			{
//				if (length < this._nReadPos)
//				{
//					return false;
//				}
				this._socket.readBytes(this._readPacket, this._nReadPos, 1);
				this._nReadPos+=1;
				this._ndx+=1;
				if (this._nReadPos < this.PACKET_HEADER_SIZE)
				{
				}
				if (this._nReadPos > length)
				{
					break;
				}
			} while (this._ndx < length)
			printBytes("接收：", this._readPacket);
			if (this._nReadPos < this.PACKET_HEADER_SIZE)
			{
				return false;
			}
			return true;
		}

		private function parseHeader():Boolean
		{
			if (this.getHead() != 29099)
			{

				return false;
			}

			var _loc_2:*=this.getCmd();
			this._nBodyLen=this.getBodyLen();
			if (this._nBodyLen >= 0)
			{
			}
			if (this._nBodyLen < this.PACKET_BUFFER_SIZE - 2)
			{
				this._readPacket.position=this.PACKET_HEADER_SIZE;
				return true;
			}
			return false;
		}

		private function parseBody(param1:int):Boolean
		{
			var _loc_2:*=this._nBodyLen + this.PACKET_HEADER_SIZE - this._nReadPos;
			var _loc_3:*=param1 - this._ndx;
			if (_loc_2 <= 0)
			{
				return true;
			}
			if (_loc_3 <= 0)
			{
				return false;
			}
			var _loc_4:*=_loc_3 < _loc_2 ? (_loc_3) : (_loc_2);
			var _loc_5:*=this._readPacket.length + _loc_4;
			if (_loc_5 > this.PACKET_BUFFER_SIZE)
			{
				return false;
			}
			this._socket.readBytes(this._readPacket, this._readPacket.position, _loc_4);
			this._nReadPos=this._nReadPos + _loc_4;
			this._ndx=this._ndx + _loc_4;
			if (this._nReadPos < this._nBodyLen)
			{
				this._readPacket.position=this._nReadPos;
				return false;
			}
			return true;
		}

		public function getHead():int
		{
			this._readPacket.position=0;
			return this._readPacket.readInt();
		}

		public function getLength():int
		{
			this._readPacket.position=4;
			return this._readPacket.readInt();
		}

		public function getCmd():int
		{
			this._readPacket.position=8;
			return this._readPacket.readShort();
		}

		public function getBodyLen():int
		{
			this._readPacket.position=2;
			return this._readPacket.readShort();
		}

		public function readBegin():void
		{
//			this.readBodyPos=this.PACKET_HEADER_SIZE;
			this.readBodyPos=0; //因为_readPacket只有data部分的内容，头部不包含
			return;
		}

		public function readInt():int
		{
			this._readPacket.position=this.readBodyPos;
			this.readBodyPos=this.readBodyPos + 4;
			return this._readPacket.readInt();
		}

		public function readUInt():uint
		{
			this._readPacket.position=this.readBodyPos;
			this.readBodyPos=this.readBodyPos + 4;
			return this._readPacket.readUnsignedInt();
		}

		public function readFloat():Number
		{
			this._readPacket.position=this.readBodyPos;
			this.readBodyPos=this.readBodyPos + 4;
			return this._readPacket.readFloat();
		}

		public function readShort():int
		{
			this._readPacket.position=this.readBodyPos;
			this.readBodyPos=this.readBodyPos + 2;
			return this._readPacket.readShort();
		}

		public function readByte():int
		{
			this._readPacket.position=this.readBodyPos;
			this.readBodyPos+=1;
			return this._readPacket.readByte();
		}

		public function readBytes():ByteArray
		{
			this._readPacket.position=this.readBodyPos;
			var len:int=this._readPacket.readUnsignedInt();
			this.readBodyPos+=4;
			if (len < 1)
				return null;
			var bytes:ByteArray=new ByteArray;
			this._readPacket.readBytes(bytes, 0, len);
			this.readBodyPos+=len;
			return bytes;
		}

		public function readString():String
		{
			this._readPacket.position=this.readBodyPos;
			this.readBodyPos=this.readBodyPos + 4;
			var length:*=this._readPacket.readUnsignedInt();
			this._readPacket.position=this.readBodyPos;
			this.readBodyPos=this.readBodyPos + length;
			return this._readPacket.readMultiByte(length, "utf-8");
		}

		public function readgb2132String():String
		{
			this._readPacket.position=this.readBodyPos;
			this.readBodyPos=this.readBodyPos + 4;
			var _loc_1:*=this._readPacket.readUnsignedInt();
			this._readPacket.position=this.readBodyPos;
			this.readBodyPos=this.readBodyPos + _loc_1;
			return this._readPacket.readMultiByte(_loc_1, "gb2132");
		}

		public function readBinary():Object
		{
			this._readPacket.position=this.readBodyPos;
			this.readBodyPos=this.readBodyPos + 4;
			var _loc_1:*=this._readPacket.readUnsignedInt();
			this._readPacket.position=this.readBodyPos;
			this.readBodyPos=this.readBodyPos + _loc_1;
			var _loc_2:*=new ByteArray();
			this._readPacket.readBytes(_loc_2, 0, _loc_1);
			return _loc_2.readObject();
		}

		public function readXml():XML
		{
			return new XML(readString());
		}

		public function readDateString():String
		{
			return readShort() + "-" + readByte() + "-" + readByte() + " " + readByte() + ":" + readByte() + ":" + readByte();
		}

		public function readDate():Date
		{
			var _loc_1:*=readShort();
			var _loc_2:*=readByte() - 1;
			var _loc_3:*=readByte();
			var _loc_4:*=readByte();
			var _loc_5:*=readByte();
			var _loc_6:*=readByte();
			var _loc_7:*=new Date(_loc_1, _loc_2, _loc_3, _loc_4, _loc_5, _loc_6);
			return _loc_7;
		}

		public function sendCmd():void
		{
			if (this._connected)
			{
				printBytes("输出", this._packet, true);
				this._socket.writeBytes(this._packet, 0, this._packetLen + this.PACKET_HEADER_SIZE);
				this._socket.flush();
			}
			else
			{
				//发送一个全局未连接消息
				ApplicationFacade.getInstance().sendNotification(CLZNoticeName.MAINMEDIATOR_SOCKET_UNCONNECTED);
				reConnect();
			}
			return;
		}

		public function reConnect():void
		{
			trace("重连服务器reConnect==>");
			this._socket.connect(this._host, this._port);
		}

		public function printBytes(msg:String, bytes:ByteArray, hasHeader:Boolean=false):void
		{
			var result:String=msg + " length: " + bytes.length + " content:";
			if (length < 500)
			{
				if (hasHeader)
				{
					for (var i:int=0; i < bytes.length; i++)
					{
						result+=bytes[i].toString(16) + ",";
						if (i == 21)
						{
							result+="["
						}
					}
					result+="]]";

				}
				else
				{

					for (var i:int=0; i < bytes.length; i++)
					{
						result+=bytes[i].toString(16) + ",";
					}
					result+="]";
				}
			}
			else
			{
				result+="..无限省略..";
			}
			trace(result);
		}

		public function close():void
		{
			this.clearEvent();
			if (this._connected)
			{
				this._connected=false;
				this._socket.close();
				this._socket=null;
			}
			return;
		}

		private function connectFun(event:Event):void
		{
			trace("连接服务器成功");
			this._connected=true;
			this.clearEvent();
			this._socket.addEventListener(ProgressEvent.SOCKET_DATA, this.socketDataFun);
			this._socket.addEventListener(Event.CLOSE, this.closeFun);
			dispatchEvent(new TcpSocketEvent(TcpSocketEvent.CONNECT));
			CLZTiming.remove(this.reConnect);
			return;
		}

		private function closeFun(event:Event):void
		{
			trace("socket have been closed");
			this._connected=false;
			//断线重连,恢复connect事件
			if (!this._socket.hasEventListener(IOErrorEvent.IO_ERROR))
			{
				this._socket.addEventListener(IOErrorEvent.IO_ERROR, this.errorFun);
			}
			if (!this._socket.hasEventListener(SecurityErrorEvent.SECURITY_ERROR))
			{
				this._socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, this.securityerrfun);
			}
			if (!this._socket.hasEventListener(Event.CONNECT))
			{
				this._socket.addEventListener(Event.CONNECT, this.connectFun);
			}
			CLZTiming.add(5, this.reConnect);
			dispatchEvent(new TcpSocketEvent(TcpSocketEvent.CLOSE));
			return;
		}

		private function securityerrfun(event:SecurityErrorEvent):void
		{
			trace("securityerrfun");
			CLZTiming.add(5, this.reConnect);
//			this.close();
			dispatchEvent(new TcpSocketEvent(TcpSocketEvent.SECURITYERROR));
			return;
		}

		private function errorFun(event:IOErrorEvent):void
		{
			trace("IOError:" + this._host + " " + this._port);
			CLZTiming.add(5, this.reConnect);
//			this.close();
			dispatchEvent(new TcpSocketEvent(TcpSocketEvent.ERROR));
			return;
		}

		public var datalen:int=0;
		public var cmd:int=0;
		public var empty1:int=0;
		public var empty2:int=0;
		public var empty3:int=0;

		public var readbodypos:int=0;


		private function socketDataFun(event:ProgressEvent):void
		{
			trace("receive data!");
			//解包，判断头部，在判断长度，若头部错误，直接清空，若长度不够，则，等待下个包，若长度够，触发一个事件
			do
			{
				switch (this._nStatus)
				{
					case this.REQ_REQUEST:
					case this.REQ_HEADER:
					{
						var length:int=this._socket.bytesAvailable;
						//如果包小于头部，等下次在读取
						if (length < PACKET_HEADER_SIZE)
						{
							this._nStatus=this.REQ_ERROR
							break;
						}
						var head:int=this._socket.readInt();
						var valid:Boolean=true;
						if (head != this.HEADER)
						{
							valid=false;
						}
						datalen=this._socket.readInt();
						//如果长度小于0.不合法，删数据
						if (datalen < 0)
						{
							valid=false;
						}
						if (!valid)
						{
							var length:int=this._socket.bytesAvailable;
							//不合法数据清空
							for (var i:int=0; i < length; i++)
							{
								this._socket.readByte();
							}
							this._nStatus=this.REQ_ERROR
							break;
						}
						cmd=this._socket.readShort();
						empty1=this._socket.readInt();
						empty2=this._socket.readInt();
						empty3=this._socket.readInt();
						if (datalen == 22)
						{
							this._nStatus=this.REQ_DONE;
							break;
						}
						length=this._socket.bytesAvailable;
						//如果包完整，全部读取，否则，等下次读包体部分，设置状态
						if (datalen - 22 <= length)
						{
							this._socket.readBytes(this._readPacket, 0, datalen - 22);
							this._nStatus=this.REQ_DONE;
							break;
						}
						else
						{
							this._socket.readBytes(this._readPacket, 0, length);
							this.readBodyPos=length;
							this._nStatus=this.REQ_BODY;
							break;
						}

					}
					//由于只解读了head，所以必须判断包体长度足够，在读取
					case this.REQ_BODY:
					{
						var length:int=this._socket.bytesAvailable;
						//毡包了，等下次读取
						if (length == 0)
							return;
						if (datalen - 22 <= readBodyPos + length)
						{
							this._socket.readBytes(this._readPacket, readBodyPos, datalen - 22 - readBodyPos);
							this._nStatus=this.REQ_DONE;
							break;
						}
						else
						{
							this._socket.readBytes(this._readPacket, readBodyPos, length);
							this.readBodyPos+=length;
							this._nStatus=this.REQ_BODY;
							break;
						}
					}
					default:
					{
						this.reset();
						return;
						break;
					}
				}
				if (this._nStatus == this.REQ_DONE)
				{
					var tcpEvent:TcpSocketEvent=new TcpSocketEvent(TcpSocketEvent.SYNC);
					this.dispatchEvent(tcpEvent);
					tcpEvent=null;
					this.reset();
				}

			} while (this._nStatus != this.REQ_ERROR || this._nStatus != this.REQ_BODY);
			if (this._nStatus == this.REQ_ERROR)
			{
				this.reset();
			}
		}

		public function printBodyData():void
		{
			printBytes("接收到网络包长" + (this._readPacket.length + this.PACKET_HEADER_SIZE) + " 接收bodydata部分：", this._readPacket);
		}

		private function socketDataFun0(event:ProgressEvent):void
		{
			var tcpEvent:TcpSocketEvent=null;
			this._ndx=0;
			var length:*=this._socket.bytesAvailable;
			do
			{
				switch (this._nStatus)
				{
					case this.REQ_REQUEST:
					case this.REQ_HEADER:
					{
						if (!this.readHeader(length))
						{
							var length:int=this._socket.bytesAvailable;
							//不合法数据清空
							for (var i:int=0; i < length; i++)
							{
								this._socket.readByte();
							}
							break;
						}
						else
						{
							this._nStatus=this.REQ_BODY;
						}
					}
					case this.REQ_BODY:
					{
						if (this.parseBody(length))
						{
							this._nStatus=this.REQ_DONE;
						}
						break;
					}
					default:
					{
						return;
						break;
					}
				}
				if (this._nStatus == this.REQ_ERROR)
				{
					return;
				}
				if (this._nStatus == this.REQ_DONE)
				{
					tcpEvent=new TcpSocketEvent(TcpSocketEvent.SYNC);
					dispatchEvent(tcpEvent);
					tcpEvent=null;
					this.reset();
				}
				if (this._ndx < length)
				{
				}
			} while (this._nStatus != this.REQ_ERROR)
			printBytes("接收：", this._readPacket);
			return;
		}

		private function clearEvent():void
		{
			if (this._socket != null)
			{
				if (this._socket.hasEventListener(IOErrorEvent.IO_ERROR))
				{
					this._socket.removeEventListener(IOErrorEvent.IO_ERROR, this.errorFun);
				}
				if (this._socket.hasEventListener(Event.CONNECT))
				{
					this._socket.removeEventListener(Event.CONNECT, this.connectFun);
				}
				if (this._socket.hasEventListener(ProgressEvent.SOCKET_DATA))
				{
					this._socket.removeEventListener(ProgressEvent.SOCKET_DATA, this.socketDataFun);
				}
				if (this._socket.hasEventListener(Event.CLOSE))
				{
					this._socket.removeEventListener(Event.CLOSE, this.closeFun);
				}
				if (this._socket.hasEventListener(SecurityErrorEvent.SECURITY_ERROR))
				{
					this._socket.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, this.securityerrfun);
				}
			}
			return;
		}

		public function getHost():String
		{
			return this._host;
		}

		public function getPort():int
		{
			return this._port;
		}

		public function getConnecState():Boolean
		{
			return this._connected;
		}

	}
}
